package com.sczmgk.hotline_pzh.photo.entity;

import android.os.Parcel;
import android.os.Parcelable;

public class PictureData implements Parcelable{
    
    public class UrlOrPathStata{
        public static final int STATE_URL = 1;
        
        public static final int STATE_PATH = 2;
    }
	/**
	 * 图片url地址
	 */
	private String mUrl;
	
	/**
	 * 图片缩放类型
	 */
	private String mType;
	
	/**
	 * 图片下标
	 */
	private int index;
	
	/**
	 * 路径类型，1.URL    2.PATH  
	 */
	private int urlOrPath;
	
	/**
	 * 是否处于选中状态
	 */
	private boolean isSelect;

	public String getmUrl() {
		return mUrl;
	}

	public void setmUrl(String mUrl) {
		this.mUrl = mUrl;
	}

	public String getmType() {
		return mType;
	}

	public void setmType(String mType) {
		this.mType = mType;
	}
	
	public void setSelect(boolean select){
		isSelect = select;
	}
	
	public boolean isSelect(){
		return isSelect;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
	
	public int getUrlOrPath() {
        return urlOrPath;
    }

    public void setUrlOrPath(int state) {
        this.urlOrPath = state;
    }

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
        // 1.必须按成员变量声明的顺序封装数据，不然会出现获取数据出错
        // 2.序列化对象  
		 dest.writeString(mUrl); 
        dest.writeString(mType); 
        dest.writeInt(index); 
        dest.writeInt(urlOrPath); 
        dest.writeInt(isSelect?1:0);
	}
	
	 // 1.必须实现Parcelable.Creator接口,否则在获取Person数据的时候，会报错，如下：  
    // android.os.BadParcelableException:  
    // Parcelable protocol requires a Parcelable.Creator object called  CREATOR on class com.um.demo.Person  
    // 2.这个接口实现了从Percel容器读取Person数据，并返回Person对象给逻辑层使用  
    // 3.实现Parcelable.Creator接口对象名必须为CREATOR，不如同样会报错上面所提到的错；  
    // 4.在读取Parcel容器里的数据事，必须按成员变量声明的顺序读取数据，不然会出现获取数据出错  
    // 5.反序列化对象  
    @SuppressWarnings("unchecked")
	public static final Creator<PictureData> CREATOR = new Creator(){
        public PictureData createFromParcel(Parcel source) {  
            // 必须按成员变量声明的顺序读取数据，不然会出现获取数据出错
        	PictureData p = new PictureData();  
            p.setmUrl(source.readString());
            p.setmType(source.readString());  
            p.setIndex(source.readInt());
            p.setUrlOrPath(source.readInt());
            p.setSelect(source.readInt()==1?true:false);
            return p;  
        }  
        public PictureData[] newArray(int size) {  
            return new PictureData[size];
        }  
    };  
}
